<!-- 登录信息  -->
<%-- <div class="pull-left image">
    <img src="<%=basePath%>/images/avatar.png" class="img-circle" alt="User Image">
</div> --%>
<%@include file="../comjs.jsp"%>
<div class="pull-left info">
    <p style="width:130px;">Hello,
    	 <a href="javascript:void(0);" onclick="showUserInfo()" style="cursor: pointer;">
    	 <%=taccount %>
    	 </a></p>
    <p style="width:130px;">
        <label id="loginRoleName"><%=troleName %></label>
    </p>
    <p style="width:150px;">
    	<a href="javascript:void(0);" id="updatePwd">
            <i class="fa fa-edit"></i>
             修改密码
        </a>
        <a href="javascript:void(0);" style="margin-left:15px;" id="logout">
            <i class="fa fa-sign-out"></i>
            退出
        </a>
    </p>
</div>
<div id="lookUserInfoDiv" style="display:none;">
	<form class="com-addForm" id="com-addForm" action="javascript:void(0)" method="post" name="searchModForm">
		<table style="width:400px;">
			<tr>
				<td  width="20%" class="tr">账号：
				</td>
				<td width="30%" class="tl" name="name" >
				</td>
	              <td width="20%" class="tr">名称：</td>
	              <td width="30%" class="tl" name="realName" >
	              </td>
	          </tr>
	          <tr>
	              <td class="tr">所属部门：</td>
	              <td class="tl" name="deptName" >
	              </td>
	              <td class="tr">所属职务：</td>
	              <td class="tl" name="dutiesName">
	              </td>
	          </tr>
	          <tr>
	              <td class="tr">入职日期：</td>
	              <td class="tl" name="entryTime">
	              </td>
	              <td class="tr">身份证：</td>
	              <td class="tl"  name="identity">
	              </td>
	          </tr>
	          <tr>
	              <td class="tr">生日：</td>
	              <td class="tl" name="birthday">
	              </td>
	              <td class="tr">年龄：</td>
	              <td class="tl" name="age">
	              </td>
	          </tr>
	          <tr>
	              <td class="tr">身体状况：</td>
	              <td class="tl"  colspan="3" name="healthStatus">
	              </td>
			</tr>
		</table>
	</form>
</div>
<div id="updatePwdDiv" style="display:none;">
	<form class="com-addForm" id="com-addForm" action="javascript:void(0)" method="post" name="searchModForm">
		<table class="dialogTable" style="width:100%;">
			<tr>
				<td class="tr">
					<label class="initStart">*</label>原密码：
				</td>
				<td class="tl"><input type="password" id="opwd" name="opwd" class="com-inp fr-text"/></td>
			</tr>
			<tr>
				<td class="tr">
					<label class="initStart">*</label>新密码：
				</td>
				<td class="tl"><input type="password" id="pwd" name="pwd" class="com-inp fr-text"/></td>
			</tr>
			<tr>
				<td class="tr">
					<label class="initStart">*</label>重复密码：
				</td>
				<td class="tl"><input class="com-inp fr-text" id="rpwd" type="password" name="rpwd"/></td>
			</tr>
		</table>
	</form>
</div>
<script>
function showUserInfo(){
	var url = 'common/LoginCtrl/getCurrentUserInfo';
	var params ={};
	var cb = function(data){
		if(data.resultCode==1){
			var ret=data.result;
			for(var i in ret){
				var text=ret[i];
				if(i=='entryTime'||i=='birthday'){
					text=text==null?'':(new Date(text)).format('yyyy-MM-dd');
				}
				$('#com-addForm td[name="'+i+'"]').html(text);
			}
		}
	};
	sendApiNoLoadSync(url, params, cb, 'POST');
	art.dialog({
		content:$('#lookUserInfoDiv').html(),
	    title: '个人信息',
	    width: 500,
	    top:100,
	    cancel: true
	});
}
var loginInfo= {
	bindEvent:function(){
		//修改密码
		$('#updatePwd').on('click',function(){
			art.dialog({
				lock: true,
				content:$('#updatePwdDiv').html(),
			    title: '修改密码',
			    width: 400,
			    top:100,
			    ok: function () {
			    	var opwd=$.trim($('#opwd').val());
			    	var pwd=$.trim($('#pwd').val());
			    	var rpwd=$.trim($('#rpwd').val());
			    	if(opwd==''){
			    		alert('原密码不能为空！');
			    		return false;
			    	}
			    	if(pwd==''){
			    		alert('新密码不能为空！');
			    		return false;
			    	}
			    	if(rpwd==''){
			    		alert('重复密码不能为空！');
			    		return false;
			    	}
			    	if(pwd!=rpwd){
			    		alert('两次密码输入不一致！');
			    		return false;
			    	}
			    	var ret=true;
			    	var url = 'common/LoginCtrl/updateUserPwd';
			    	var params = {
		    			'opwd':opwd,
		    			'pwd':pwd
		    		};
		    		var cb = function(data) {
		    			if (data.resultCode != 1) {
		    				alert(data.msg);
		    				ret=false;
		    			}else{
		    				alert('修改成功！');
		    			}
		    		};
		    		sendApiNoLoadSync(url, params, cb, 'POST');
		    		if(!ret)
		    			return false;
			    },
			    cancel: true
			});
		});

		//退出
		$('#logout').on('click',function(){
			var url = 'common/LoginCtrl/loginOut';
			var params = {};
			var cb = function(data) {
				if (data.resultCode != 1) {
					alert(data.msg);
				}else{
					var url=APP_ADDRESS+'login.jsp';
					parent.location.href=url;
				}
			};
			sendApiNoLoad(url, params, cb, 'POST');
		});
	},
	
	init:function(){
		loginInfo.bindEvent();
	}
}
$(document).ready(function() {
	loginInfo.init();
});
</script>